<?php
include("conn.php");
include_once ('class/bonus_class.php');
function wltb2(){
	$sql2="select * from `member` where isb2=1 order by plevel2,pdt2 limit 0,1";
	$query = mysql_query($sql2);
	return mysql_fetch_array($query);
}

function sqfwzx($id){
	$sql1="select * from member where ulevel=4 and reid=".$id['id'];
	$query1=mysql_query($sql1);
	if(mysql_num_rows($query1)>=2){
		return true;
	}else {
		return false;
	}
}

function getulevelss($ul){
	$sql = "SELECT * FROM `ulevel` where ulevel=".$ul." ";
	$query = mysql_query($sql);
	return mysql_fetch_array($query);
}

function huikuan($nickname){
	$sql="select * from huikuan where nickname=".$nickname." ";
	$query = mysql_query($sql);
	if(mysql_num_rows($query)==0){
		$now=now();//当前时间
		$nowdate=time()-60*60*24;//24小时
		$name=getMemberbyID($nickname);
		$shijian=$now-$name['pdt'];//当前时间减去激活时间
		if($shijian>=$nowdate){
			edit_delete_cl('member',$name['id']);
			return false;
		}else{
			return true;
		}
	}else{
		return true;
	}
}

function getpaixu($id){
	$sql="select * from member where paixu=(select max(paixu) from member) and pcid=".$id."";
	$query = mysql_query($sql);
	return mysql_fetch_array($query);
}

function getPcid($id){
	$sql="select * from member where pcid=".$id." order by id asc";
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}

function getPPcid($id){
	$sql="select * from member where pcid=".$id." and jiner<1200";
	//echo $sql;
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
//	print_r(mysql_fetch_row($query));
}
function getUlevel(){
	$sql="select * from member where ulevel=2";
	$query=mysql_query($sql);
	return mysql_num_rows($query);
}

function getNameulevel($id,$i){
	$sql = "SELECT * FROM `member` WHERE fatherid=".$id." and ulevel=".$i." and jiner>=1200";
	$query=mysql_query($sql);
	return mysql_num_rows($query);
}

function getYanZheng($id){
	 $sql="select * from `member` where yanzheng=".$id."";
	$rs=mysql_query($sql);
	return mysql_fetch_assoc($rs);
}
//日封顶
function getdaybonus($id,$riQi){
	$sql = "select * from `bonus` where bdate like '%$riQi%' and uid = ".$id."";
	$result = mysql_query($sql);
	return mysql_fetch_assoc($result);
}
//获取当前时间
function now(){
	date_default_timezone_set('PRC');
	return date('Y-m-d H:i:s',time());
}

function systemstatus(){
	$sql="SELECT xtkg FROM `systemparameters` where id=1";	
	$query=mysql_query($sql);
	$row=mysql_fetch_row($query);
	if ($row[0]==1){
		return true;
	}else{
		return false;	
	}
}
function getisbd2($id,$m){
     $sql="select * from member where reid=".$id." ";
    $query=mysql_query($sql);
    $num=0;
    while ($us=mysql_fetch_assoc($query)){
        if($us['isb2']==$m){
            $num+=1;
        }
    }
    return $num;
}
//商品插入
//$id商品id，$arr订单里所有商品的 信息，$member用户信息，$member_update用户扣除电子情况
function store($id,$arr,$member,$member_update,$lsk,$dpid,$lx,$lirun){
		$FileID='1'.date("mdHis") . '' . rand(100,999);
		$orders=array('ordersnumber'=>$FileID,'uid'=>$member['id'],'userid'=>$member['userid'],
				'username'=>$member['username'],'usertel'=>$member['usertel'],'useraddress'=>$member['sheng'].$member['shi'].$member['xian'].$member['useraddress'],
				'goods'=>serialize($arr),'cdate'=>now(),'sgb'=>$lsk,'dpid'=>$dpid,'lirun'=>$lirun,

				);
		add_insert_cl('orders',$orders);
		edit_update_cl('member',$member_update,$member['id']);
		return $FileID;
}
//消息框函数
function alert($msg,$url=""){ 
$str = "<script type='text/javascript'>"; 
$str.="alert('".$msg."');"; 
if ($url != "") 
{ 
$str.="window.location.href='{$url}';"; 
} 
else 
{ 
$str.="window.history.back();"; 
} 
echo $str.='</script>'; 
}

function getProvincebyid($pid){
	$where="where provinceid=".$pid;
	$province=que_select_cl_where('province',$where);
	return $province['province'];
}
function getCitybyid($cid){
	$where="where cityid=".$cid;
	$city=que_select_cl_where('city',$where);
	return $city['city'];
}
/*
树状图输出逻辑
@reid 推荐人
return 输出格式
*/
function tree($id){
	$shuchu = "<ul>";
	$sql = "SELECT * FROM `member` WHERE reid=".$id." order by rdt asc";
	$query = mysql_query($sql);
	if (mysql_num_rows($query)>0){
		while($row=mysql_fetch_array($query)){
			$ul=ulevel($row['ulevel']);
			$shuchu.="<li>".$row['nickname']."[".$ul['lvname']."]";
			$shuchu.=tree($row['id']);
			$shuchu.="</li>";
		}
		$shuchu .= "</ul>";
	}else{
		$shuchu="";
	}
	return $shuchu;
}
function trees($id){
	echo "sss";
	$shuchu = "<ul>";
	echo $sql = "SELECT * FROM `member` WHERE id=".$id." order by pdt limit 20";
	$query = mysql_query($sql);
	if (mysql_num_rows($query)>0){
		while($row=mysql_fetch_array($query)){
			$ul=ulevel($row['ulevel']);
			$shuchu.="<li>".$row['nickname']."[".$ul['lvname']."]";
			$shuchu.=trees($row['id']);
			$shuchu.="</li>";
		}
		$shuchu .= "</ul>";
	}else{
		$shuchu="";
	}
	return $shuchu;
}
//检查会员编号是否存在
function checkUserID($UserID){
	$sql="select * from `member` where userid='".$UserID."'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;	
	}
}
//检查会员编号是否存在
function checkUserID1($UserID,$bdid){
	$sql="select * from `member` where userid='".$UserID."' and bdid=$bdid";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;
	}
}
//检查会员编号是否存在
function checkID($ID){
	$sql="select * from `member` where id='$ID'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return false;
	}else{
		return true;
	}
}
//检查会员编号是否存在
function checkNickName($NickName){
	$sql = "SELECT * FROM `member` WHERE nickname='".$NickName."'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;	
	}
}
//检查会员编号是否存在
function checkNickName2($NickName){
	$sql = "SELECT * FROM `member` WHERE nickname='".$NickName."' and isbd>=2";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;
	}
}
//检测会员推荐几次
function Registration($id){
	$sql="SELECT * FROM `member` WHERE nickname='".$id."'";
	$query=mysql_query($sql);
	$row= mysql_fetch_array($query);
	if($row['recount']==4){
		return true;
	}else{
		return false;
	}
}

//检查会员编号是否是服务中心
function checkIsbd($NickName){
	$sql = "SELECT * FROM `member` WHERE nickname='".$NickName."' and isbd>=2";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;
	}
}

//检查会员编号是否激活
function checkNickNamebyispay($NickName){
	$sql = "SELECT * FROM `member` WHERE nickname = '$NickName' and ispay > 0 ";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;	
	}
}



//会员登录验证
function checkLogin($NickName,$PassWord){
	$PassWord = md5($PassWord);
	$sql="SELECT * FROM member WHERE nickname= '$NickName' AND password1= '$PassWord'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
 
	}else{
		return false;	
	}
}
//会员二级密码验证
function checkPassword2($NickName,$PassWord2){
	$PassWord2 = md5($PassWord2);
	$sql="SELECT * FROM member WHERE nickname='".$NickName."' AND password2='".$PassWord2."'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;	
	}
}
//会员三级密码验证
function checkPassword3($NickName,$PassWord3){
	$PassWord3 = md5($PassWord3);
	$sql="select * from `Member` where nickname='".$NickName."' AND password3='".$PassWord3."'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;	
	}
}
//密码问题验证
function checkQuestion($NickName,$passanswer){
	$sql="SELECT * FROM member WHERE nickname='".$NickName."' AND passanswer='".$passanswer."'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;	
	}
}
//根据ID获取会员信息
function getMemberbyID($_id){
 	$sql = "SELECT * FROM `member` WHERE id=".$_id;
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}//根据ID获取会员B网信息
function getBMemberbyID($_id){
 	$sql = "SELECT * FROM `bmember` WHERE userid=".$_id;
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}
//根据ID获取会员B网信息
function getBMemberby($_id){
 	$sql = "SELECT * FROM `bmember` WHERE id=".$_id;
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}
//根据ID获取会员B网信息
function getBMemberbyNickName($_id){
 	$sql = "SELECT * FROM `bmember` WHERE nickname='".$_id."'";
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}
function getMemberbyUserid($_id){
	$sql = "SELECT * FROM `member` WHERE id =".$_id;
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}
function getMemberbyName($_nickname){
	$sql = "SELECT * FROM `member` WHERE nickname =".$_nickname;
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}
//根据昵称获取会员信息
function getMemberbyNickName($NickName){
	$sql = "SELECT * FROM `member` where nickname='".$NickName."'";
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}
//检查该位置是否有人
function checkFatherMan($FatherID,$TreePlace){
	$sql = "SELECT * FROM `member` WHERE fatherid=".$FatherID." AND treeplace=".$TreePlace."";
	$query = mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;
	}
}
//获得安置位置的人的信息
function getFatherManbyFidAndTreeplace($FatherID,$TreePlace){
	$sql = "SELECT * FROM `member` WHERE fatherid=".$FatherID." AND treeplace=".$TreePlace."";
	if ($query = mysql_query($sql)){
		return mysql_fetch_array($query);
	}else{
		return "";	
	}
}
//获得安置位置的人的信息
function getFatherManbyFidAndTreeplaceBmember($FatherID,$TreePlace){
	$sql = "SELECT * FROM `bmember` WHERE fatherid=".$FatherID." AND treeplace=".$TreePlace."";
	if ($query = mysql_query($sql)){
		return mysql_fetch_array($query);
	}else{
		return "";
	}
}

//获得B网安置位置的人的信息
function getFatherManbyFidAndTreeplace2($FatherID,$TreePlace){
	$sql = "SELECT * FROM `member` WHERE fatherid2=".$FatherID." AND treeplace2=".$TreePlace."";
	if ($query = mysql_query($sql)){
		return mysql_fetch_array($query);
	}else{
		return "";	
	}
}

//查询该编号推荐的人的集合
function getMemberListByreid($reid){
	$sql = "SELECT * FROM `member` WHERE reid=".$reid."";
	$query = mysql_query($sql);
	return mysql_fetch_array($query);
}
/*判断id的团队中是否有uid
*return true在团队中,false不在
*/
function checkisppath($id,$uid){
	$re=getMemberbyID($uid);
	return preg_match(",".$id.",",$re['ppath']);
}
/*判断id的团队中是否有nickname
*return true在团队中,false不在
*/
function checkisrepath($id,$nickname){
	$re=getMemberbyNickName($nickname);
	return preg_match(",".$id.",",$re['repath']);
}

//判断是否有新邮件
function checknewmail($_id){
	$sql = "SELECT * FROM `mail` WHERE isread=0 and sid=".$_id;
	$query = mysql_query($sql);
	if(mysql_num_rows($query) >= 1){
		return true;
	}else{
		return false;
	}
}

//判断是否有新邮件
function newmailcount($_id){
	$sql = "SELECT * FROM `mail` WHERE isread=0 and sid=".$_id;
	$query = mysql_query($sql);
	return mysql_num_rows($query);
}

/*
*单条数据查询实例
*$table=表名
*$编号
*/
function que_select_cl($talbe,$id){
	$sql="select * from ".$talbe." where id=".$id."";
	if ($query=mysql_query($sql)){
		return mysql_fetch_array($query);
	}
}

/*
*单条数条件据查询实例
*$table=表名
*$条件
*/
function que_select_cl_where($talbe,$where){
	$sql="select * from ".$talbe." ".$where."";
	if ($query=mysql_query($sql)){
		return mysql_fetch_array($query);
	}
}

/*
*插入实例
*$table=表名
*$err=数组
*/
function add_insert_cl($table,$err){     
	$sql = "INSERT INTO ".$table." (";    
	foreach ( $err as $key => $value  ){    
		$sql .= $key.", ";     
	}      
	$sql = substr($sql, 0, strlen($sql)-2) .  ") VALUES (";    
	foreach ( $err as $key => $value  ){    
		$sql .= "'".addslashes($value)."', ";     
	}      
	$sql = substr($sql, 0, strlen($sql)-2) .  ")";
	@mysql_query($sql) or die (mysql_error());
	return mysql_insert_id();
}
function add_select(){
	$sql="select * from member where id=LAST_INSERT_ID()";
	$query=mysql_query($sql);
	return mysql_fetch_array($query);
}

/*
*修改实例
*$table=表名
*$err=数组
*$id=编号
*/
function edit_update_cl($table,$err,$id){     
	$sql = "UPDATE ".$table." SET ";    
	foreach ( $err as $key => $value  ){
		if(preg_match("/^\d*$/",$key)){
			#过滤数字
		}else{
			$sql .= $key."='".addslashes($value)."', ";	
		}
	}      
	$sql = substr($sql, 0, strlen($sql)-2) .  " WHERE id=".$id;
	
	@mysql_query($sql) or die (mysql_error());

}

/*根据编号删除表数据
$table表名
$id 编号
*/
function edit_delete_cl($table,$id){
	$sql = "DELETE FROM ".$table." WHERE id=".$id; 
	@mysql_query($sql) or die (mysql_error());
}

function edit_delete_all($table){
	$sql = "DELETE FROM ".$table;
	@mysql_query($sql) or die (mysql_error());
}

function edit_sql($sql){
	@mysql_query($sql) or die (mysql_error());	
}
/*
*@ulevel 等级数字
return 文字级别
*/
function ulevel($ulevel){
	$ul="";
	$ul=que_select_cl('ulevel',$ulevel);
	return $ul;	
}
function zjulevel($zjulevel){
	$zjul="";
	$zjul=que_select_cl('zjulevel',$zjulevel);
	return $zjul;	
}


/*分页处理
@ $p当前页数
@ $total总页数
@ $sum条目总数
@ $pagesize每页显示条数
return 分页文字信息
*/
function fenye($p,$pagesize,$sum,$total,$cx){
	#前5页
	$top5="<a href='?page=1".$cx."' style='text-decoration:none' title='到第1页'><<</a>&nbsp;&nbsp;";
	for($i = $p-4; $i < $p; $i++) {
		if($i>=1){
			$top5=$top5."<a href='?page=".$i."".$cx."' style='text-decoration:none' title='到第".$i."页'>".$i."</a>&nbsp;&nbsp;";
		}
	}
	$desc5="";
	for($i = $p+1; $i <= $p+4; $i++) {
		if($i<=$total){
			$desc5=$desc5."<a href='?page=".$i."".$cx."' style='text-decoration:none' title='到第".$i."页'>".$i."</a>&nbsp;&nbsp;";
		}
	}
	$desc5=$desc5."<a href='?page=".$total."".$cx."' style='text-decoration:none' title='到第".$total."页'>>></a>&nbsp;&nbsp;";
	$dianji=$top5.$p."&nbsp;&nbsp;".$desc5;
	$shuchu="每页".$pagesize."条,总共".$sum."条,当前显示第".$p."页,总共".$total."页\n\n";
	if($p > 1) //当前页不是第一页时，输出上一页的链接 
	{ 
		$prev = $p - 1; 
		$shuchu .= "<a href='?page=".$prev."".$cx."' style='text-decoration:none'>上一页</a>\n\n"; 
	}
	if($p < $total) //当前页不是最后一页时，输出下一页的链接 
	{ 
		$next = $p + 1; 
		$shuchu .= "<a href='?page=".$next."".$cx."' style='text-decoration:none'>下一页</a>"; 
	}
	return $dianji.$shuchu;
}


//得到结果集数组
function getAll($sql){
	$rs=mysql_query($sql);
    $rows=array();
	while($row=mysql_fetch_assoc($rs)){
		$rows[]=$row;
	}
	return $rows;
}

//得到一条记录
function getOne($sql){
	$rs=mysql_query($sql);
    if(!empty($rs)){
        return mysql_fetch_assoc($rs);
    }

}

//得到安置关系链
function ppath($id){
	$us=getMemberbyID($id);
	$ppath=$us['ppath'];
	$len=strlen($ppath);
	$str=substr($ppath,1,$len-2);//$len-16
	$arr=explode(",",$str);
	return $arr;
}
//读取服务中心的地区
function lol($diqu,$bdlevel){
    if($bdlevel==1){
       	$sql="select a.area,c.city,p.province from area a left join city c on a.fatherid=c.cityid left join province p on c.fatherid=p.provinceid where a.areaid={$diqu}";
        $rs=getOne($sql);
        return $rs['province'].$rs['city'].$rs['area'];
    }elseif($bdlevel==2){
        $sql="select c.city,p.province from  city c  left join province p on c.fatherid=p.provinceid where c.cityid={$diqu}";
        $rs=getOne($sql);
        return $rs['province'].$rs['city'];
    }
	
}
//会员的地区
function userdiqu($id){
	$sql="select shi,xian from member where id={$id}";
	$rs=getOne($sql);
	if($rs['xian']>0){
		$sql="select a.area,c.city,p.province from area a left join city c on a.fatherid=c.cityid left join province p on c.fatherid=p.provinceid where a.areaid={$rs['xian']}";
		$rs=getOne($sql);
		return $rs['province'].$rs['city'].$rs['area'];
	}elseif($rs['shi']>0){
		$sql="select c.city,p.province from  city c  left join province p on c.fatherid=p.provinceid where c.cityid={$rs['shi']}";
		$rs=getOne($sql);
		return $rs['province'].$rs['city'];
	}
}
//会员推荐第一人必须放置在自己层数最深的区的最下面
function relevel($rename,$fathername){
	$sql="select id,recount from member where nickname='{$rename}'";
	$rs=getOne($sql);
	if($rs['recount']==0){
		$s="select nickname from member where ppath like '%{$rs['id']}%' and ispay>0 order by plevel desc,treeplace  limit 1";

		$r=getOne($s);
		if(!empty($r)){
		    if($r['nickname']==$fathername){
		        return false;
		    }else{
		    	return true;
		    }
		}else{
			return false;
		}
		
	}
	return false;
}

function shen($id){
	$sql="select max(plevel) a from member where ppath like '%{$id}%'";
	
	$rs=getOne($sql);
	return $rs['a'];
}
//累计消费业绩
function comsumptionyeji($id,$money){
    if($id!=1){
		$sql="select reid from member where id={$id}";
		$rs=getOne($sql);
		$path=ppath($id);
		$re=",".$rs['reid'];
		if(!empty($path)){
		    $str=""; 
			foreach($path as $v){
				$str.=",".$v;
			}
		}
    }
	$s="update member set xiaofeiyeji=xiaofeiyeji+{$money} where id in ({$id}{$str}{$re})";
	mysql_query($s);
}



//select的条数
function num($sql){
	$rs=mysql_query($sql);
	return mysql_num_rows($rs);
}
//比较大小区
function big_little($id){
	$sql="select * from member where id={$id}";
	$rs=getOne($sql);
	$little=$rs['area1']>=$rs['area2']?$rs['area2']:$rs['area1'];
	$sql="select fuwuzhongxi from systemparameters where id=1";
	$rs=getOne($sql);
	if($little>=$rs['fuwuzhongxi']){
		return true;
	}
	return false;
}


//得到安置关系链
function repath($id){
    $us=getMemberbyID($id);
    $ppath=$us['repath'];
    $len=strlen($ppath);
    $str=substr($ppath,1,$len-2);//$len-16
    $arr=explode(",",$str);
    return $arr;
}
//获取最低层的会员
function treepplace($id,$num){
    $sql="select * from member where fatherid=".$id." and treeplace=".$num;
    $query=mysql_query($sql);
    $re1=mysql_fetch_assoc($query);
    $sql2="select * from member where ppath like '%".$re1['id']."%' order by plevel desc,id asc limit 0,1 ";
    $query2=mysql_query($sql2);
    if($re2=mysql_fetch_assoc($query2)){
        return $re2['id'];
    }
}
//获取会员所在的区域
function gettreeplace($id,$uid){
    $us=getMemberbyID($id);
    if($us['reid']==$uid){
        return $us['treeplace'];
    }else{
        $sql="select * from member where id in (0".$us['ppath']."0) and fatherid=".$uid;
        $query=mysql_query($sql);
        $row=mysql_fetch_assoc($query);
        return $row['treeplace'];
    }

}
//获取推荐关系的总业绩
function getrapathareat($id,$yl5){
    $sql="select * from member where reid=".$id;
    $query=mysql_query($sql);
    $sum=0;
    while ($row=mysql_fetch_assoc($query)){
        $area=$row['area1']+$row['area2'];
        if($area>=$yl5){
            $sum+=1;
        }
    }
    return $sum;
}
/**
 * 判断是否为手机登录
 * @return bool
 */

function ismobile() {
    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
        return true;

    //此条摘自TPM智能切换模板引擎，适合TPM开发
    if(isset ($_SERVER['HTTP_CLIENT']) &&'PhoneClient'==$_SERVER['HTTP_CLIENT'])
        return true;
    //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset ($_SERVER['HTTP_VIA']))
        //找不到为flase,否则为true
        return stristr($_SERVER['HTTP_VIA'], 'wap') ? true : false;
    //判断手机发送的客户端标志,兼容性有待提高
    if (isset ($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array(
            'nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile'
        );
        //从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return true;
        }
    }
    //协议法，因为有可能不准确，放到最后判断
    if (isset ($_SERVER['HTTP_ACCEPT'])) {
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
            return true;
        }
    }
    return false;
}
//查询见点表
function jianmey($id,$cha){
    $sql="select * from koujiandian  where uid=".$id." and ceng=".$cha." ";
    $jiandian=getOne($sql);
    return $jiandian;
}

function addjiandianmey($id,$cha,$jine){
        $jiandian_add=null;
        $jiandian_add['ceng']=$cha;
        $jiandian_add['jine']=$jine;
        $jiandian_add['uid']=$id;
        add_insert_cl('koujiandian',$jiandian_add);
}
function updatejiandianmey($jjine,$zjine,$jid,$jine,$uid){
    $bonus=new bonus_class();
    $row=getMemberbyID($uid);
        if($jjine+$jine>$zjine){
            $yue=$zjine-$jjine;
            $add_jine=$zjine;
            $bjine=$yue;
        }else{
            $yue=0;
            $add_jine=$jjine+$jine;
            $bjine=$jine;
        }
        $jiandian_add['jine']=$add_jine;
        edit_update_cl('koujiandian',$jiandian_add,$jid);
        $beizhu='扣除升级费用';
        $bonus->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],11,$bjine,$beizhu);
        return $jine-$yue;
}
//根据安置关系判断星级会员极差人数
function xingji($uid,$nickname,$rep,$rel,$isb2){
    $sql="select * from `member` where id in(0".$rep."0) and ".$rel."-plevel<=".$rel." and ulevel2>0 and ulevel>1 order by plevel desc ";
    $num=0;
    if($query = mysql_query($sql)) {
        while ($row = mysql_fetch_array($query)) {
            if($row['ulevel2']==$isb2){
                $num+=1;
            }else{
                if($row['ulevel2']>$isb2){
                    break ;
                }
            }
        }
    }
    return $num;
}
//curl 访问
function https_request($url,$data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

/**
 *生成唯一订单号
 *
 */
function build_ordernumber(){
    $order = 'cz'.date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    $sql="select * from chongzhi where orderid='".$order."'";
    $isexist=getOne($sql);
    if($isexist){
        build_ordernumber();
    }else{
        return $order;
    }
}
?>